{%- set ips = [] %}
{%- for host in groups[zk_inventory_group] %}
{% if host == inventory_hostname %}
{%- set zk_address_local = '0.0.0.0' %}
{% else %}
{%- set zk_address_local = hostvars[host]['zk_address'] %}
{% endif %}
{{- ips.append(dict(id=loop.index, host=host, ip=zk_address_local, role=hostvars[host]['zk_server_role'])) }}
{%- endfor %}

{% for server in ips %}
{% if server.host is defined %}
{% if server.ip is defined %}
server.{{server.id}}={{server.ip}}:2888:3888:{{ server.role | default ("participant") }};{{ zk_client_port }}
{% else %}
server.{{server.id}}={{server.host}}:2888:3888:{{ server.role | default ("participant") }};{{ zk_client_port }}
{% endif %}
{% else %}
server.{{loop.index}}={{server}}:2888:3888:{{ server.role | default ("participant") }};{{ zk_client_port }}
{% endif %}
{% endfor %}
